import { goods } from '../goods'
import { user } from '../user/user'
import { bag } from '../user/user_bag'
import { race_base } from '../basement/race_base'
import { race_extra } from '../basement/race_extra'
import { drop_list } from '../basement/drop_list'
import { letters } from '../user/letters'
import { main_story } from '../stroy/main_story'
import { user_equipment } from '../user/user_equipment'
import { user_attribute } from '../user/user_attribute'
import { equipment_list } from '../item/equipment_list'
import { battle } from '../battle/battle'
import { team } from '../battle/team'
import { skill_list } from '../skills/skill_list'
import { user_skill } from '../user/user_skill'
import { map_infor } from '../maps/map_infor'
import { map_location } from '../maps/map_location'
import { map_setting } from '../maps/map_setting'

/**
 * 如果数据库中不存在 user 表则自动创建，包含当前文件中的所有字段和约束
 * @returns Promise<void>
 */
export async function ensureUserTable(): Promise<void> {
  // sync({ alter: true }) 可自动调整表结构，sync() 只在不存在时创建
  await user.sync()
  await bag.sync()
  await goods.sync()
  await letters.sync()
  await main_story.sync()
  await race_base.sync()
  await race_extra.sync()
  await user_equipment.sync()
  await user_attribute.sync()
  await equipment_list.sync()
  await battle.sync()
  await team.sync()
  await skill_list.sync()
  await drop_list.sync()
  await user_skill.sync()
  await map_infor.sync()
  await map_location.sync()
  await map_setting.sync()
  // 以上表都需要在数据库中存在，否则会抛出错误
}
